# 导包
import requests
import app


class IHRMAPI:
    """ 创建封装的接口类 """
    def __init__(self):
        # 定义登录的URL
        self.login_url = app.BASE_URL + "/api/sys/login"
        self.add_emp_url = app.BASE_URL + "/api/sys/user"

    def login(self, request_body):
        """登录的封装"""
        return requests.post(url=self.login_url,
                             headers=app.HEADERS,
                             json=request_body)

    def add_emp(self, request_body):
        """添加的封装"""
        return requests.post(url=self.add_emp_url,
                             headers=app.HEADERS,
                             json=request_body)

    def query_emp(self, emp_id):
        """查询的封装"""
        query_url = self.add_emp_url + "/" + emp_id
        print("查询员工的url为：", query_url)
        return requests.get(url=query_url,
                            headers=app.HEADERS)

    def modify_emp(self, emp_id, request_body):
        """修改的封装"""
        modify_url = self.add_emp_url + "/" + emp_id
        print("修改员工的url为：", modify_url)
        return requests.put(url=modify_url,
                            headers=app.HEADERS,
                            json=request_body)

    def delete_emp(self, emp_id):
        """删除的封装"""
        delete_url = self.add_emp_url + "/" + emp_id
        print("删除员工的url为：", delete_url)
        return requests.delete(url=delete_url,
                               headers=app.HEADERS)

# ihrm_api = IHRMAPI()
# request_body_value = {"mobile": "13800000002", "password": "123456"}
# response = ihrm_api.login(request_body_value)
# print(response.text)
